package com.huangmb.anymark.server.service.impl;

import com.huangmb.anymark.server.dao.BaseDao;
import com.huangmb.anymark.server.service.BaseService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * @author hmb
 * @version 1.0
 * @since 2016/5/4 21:08
 */
@Transactional
public  class BaseServiceImpl<T> implements BaseService<T> {


    private BaseDao<T> mDao;
    /**
     * 子类必须继承该方法注入相应的DAO
     * */
    public void setDao(BaseDao<T> dao){
        this.mDao = dao;
    }
    @Override

    public void save(T entity) {
        mDao.save(entity);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void update(T entity) {
        mDao.update(entity);
    }

    @Override
    public void delete(Serializable id) {
        mDao.delete(id);
    }

    @Override
    @Transactional(readOnly = true)
    public T getById(Serializable id) {
        return mDao.findById(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<T> getByHQL(String hql, Object... params) {
        return mDao.findByHQL(hql, params);
    }
}
